﻿package plugin.weiduan
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import flash.external.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import uiresource.weiduan.*;
    import view.mornExtends.*;
    import vo.*;

    public class WeiDuanUICtrl extends NewWeiDuanUI
    {
        private var itemSprite:Sprite;
        private var mc:XMLMovieClip;

        public function WeiDuanUICtrl()
        {
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            this.itemSprite = new Sprite();
            this.itemSprite.x = 46;
            this.itemSprite.y = 294;
            this.addChild(this.itemSprite);
            xiazaiBtn.skin = "png.weiduan.btn_lingqu";
            xiazaiBtn.addEventListener(MouseEvent.CLICK, this.onXiaZai);
            if (Config.gameParams.client == 2)
            {
                xiazaiBtn.skin = "png.weiduan.btn_lq";
            }
            else
            {
                xiazaiBtn.skin = "png.weiduan.btn_lingqu";
                XMLMcManager.instance.complatefuncs["weiduandenglu"] = this.mcCompletefunc;
            }
            this.addItem();
            closeBtn.addEventListener(MouseEvent.CLICK, this.onClose);
            return;
        }// end function

        private function mcCompletefunc() : void
        {
            this.mc = XMLMcManager.instance.getPluginMc("weiduandenglu", "weiduan");
            if (this.mc)
            {
                this.addChild(this.mc);
                this.mc.blendMode = BlendMode.ADD;
                this.mc.mouseChildren = false;
                this.mc.mouseEnabled = false;
                this.mc.x = xiazaiBtn.x;
                this.mc.y = xiazaiBtn.y - 22;
                this.mc.play();
            }
            return;
        }// end function

        private function addItem() : void
        {
            var _loc_7:String = null;
            var _loc_8:Array = null;
            var _loc_9:Object = null;
            var _loc_1:* = ConfigDictionary.data.box;
            var _loc_2:* = ConfigDictionary.data.item;
            var _loc_3:* = _loc_1[5];
            var _loc_4:* = (_loc_3.items as String).split(";");
            var _loc_5:Array = [];
            var _loc_6:int = 0;
            while (_loc_6 < _loc_4.length)
            {
                
                _loc_7 = _loc_4[_loc_6];
                _loc_8 = _loc_7.split("-");
                _loc_9 = ItemObject.create(_loc_2[_loc_8[0]]);
                _loc_9.count = _loc_8[1];
                _loc_5.push(_loc_9);
                _loc_6++;
            }
            list_goods.array = _loc_5;
            list_goods.renderHandler = new Handler(this.goodsRender);
            return;
        }// end function

        private function goodsRender(param1:Component, param2:int) : void
        {
            if (param2 < list_goods.length)
            {
                (param1 as FlashItem).effshow = true;
                (param1 as FlashItem).data = list_goods.array[param2];
            }
            return;
        }// end function

        private function onXiaZai(event:MouseEvent) : void
        {
            if (Config.gameParams.client == 2)
            {
                PluginManager.instance.sendToServer("xunbao", CMDXunBao.getClientReward, null);
                this.close();
                ModelProxy.change("mainui", "removeBtn", "weiduandenglu");
                this.clearEffect();
            }
            else
            {
                ExternalInterface.call("getMicroClient");
                ModelProxy.change("movetips", "error", "前往下载微端");
            }
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            this.clearEffect();
            return;
        }// end function

        private function clearEffect() : void
        {
            if (this.mc)
            {
                if (this.mc.parent)
                {
                    this.mc.parent.removeChild(this.mc);
                }
                this.mc.stop();
            }
            return;
        }// end function

        private function close() : void
        {
            PluginManager.instance.closePlugin("weiduandenglu");
            return;
        }// end function

    }
}
